package org.dromara.system.api.feign.fallback;

import cn.hutool.http.HttpStatus;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.system.api.feign.SystemUserClient;
import org.dromara.system.api.domain.bo.RemoteUserBo;
import org.dromara.system.api.domain.vo.RemoteUserVo;
import org.dromara.common.core.domain.model.LoginUser;
import org.dromara.common.core.domain.model.XcxLoginUser;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author: zhou shuai
 * @date: 2024/9/26 20:23
 * @version: v1
 */
@Slf4j
@Component
public class SystemUserFallBack implements FallbackFactory<SystemUserClient> {

    @Override
    public SystemUserClient create(Throwable throwable) {
        log.error("SystemUserFallBack, cause:{}", throwable.getMessage());
        return new SystemUserClient() {

            @Override
            public R<LoginUser> getUserInfoByUserName(String userName, String tenantId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<LoginUser> getUserInfoByUserId(Long userId, String tenantId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<LoginUser> getUserInfoByPhoneNumber(String phoneNumber, String tenantId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<LoginUser> getUserInfoByEmail(String email, String tenantId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<XcxLoginUser> getUserInfoByOpenId(String openId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<Boolean> userRegister(RemoteUserBo remoteUserBo) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<Boolean> resetUserPas(Long userId, String password) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<String> selectUserNameById(Long userId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<String> selectNickNameById(Long userId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<String> selectPostnameById(Long userId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<String> selectRolenameById(Long userId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<String> selectNickNameByIds(String userIds) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<String> selectPhonenumberById(Long userId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<String> selectEmailById(Long userId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<Void> recordLoginInfo(Long userId, String ip) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<List<RemoteUserVo>> selectListByIds(List<Long> userIds) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<List<Long>> selectUserIdsByRoleIds(List<Long> roleIds) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<List<RemoteUserVo>> selectUsersByRoleIds(List<Long> roleIds) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<List<RemoteUserVo>> selectUsersByDeptIds(List<Long> deptIds) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<List<RemoteUserVo>> selectUsersByPostIds(List<Long> postIds) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<Map<Long, String>> selectUserNamesByIds(List<Long> userIds) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<LoginUser> getUserInfo() {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

        };
    }

}
